<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with class object pgraphics - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=class+object+pgraphics</link>
      <pubDate>Sun, 08 Aug 2021 17:59:46 +0000</pubDate>
         <description>Tagged with class object pgraphics - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedclass+object+pgraphics/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>PGraphics unpredictable and unconsistent behaviour in Android mode</title>
      <link>https://forum.processing.org/two/discussion/27614/pgraphics-unpredictable-and-unconsistent-behaviour-in-android-mode</link>
      <pubDate>Sun, 01 Apr 2018 10:59:16 +0000</pubDate>
      <dc:creator>ScemEnzo</dc:creator>
      <guid isPermaLink="false">27614@/two/discussions</guid>
      <description><![CDATA[<p>I'm developing an Android live wallpaper and I'm struggling with various problems the PGraphics objects have when rendering.
The main problem is the impossibility to clear a PGraphics object with alpha values every frame, and everything I've tried works lika a charm in Java mode.</p>

<p>I'm using P2D as main renderer and the default for the Graphics object one because I whant to obtain a scaled pixel effect using the OpenGL nearest neighbor trick, but that same trick cannot be applied to a PGraphics rendering (so I use default + noSmooth() for this one).
After Drawn everything on the PGraphic object, I scale the image on screen using the copy() method.</p>

<p>The result should be an image composed by PImage and PGraphics objects, but these last does not clean after a clear() or background(0,0) call so the image upon them is additive.
The clear() call in particular gives me a tiny performances drop, while background(255,255) does its job so it's working fine as method.</p>

<p>I've tried every possible turnaround but nothing has the same performances/appearence as should be in this common way not working because of these problems.
I don't know if I'm missing something or if I'm too stupid to figure out a simple solution.</p>

<p>here is a piece of the code that works on Java mode and does not work in Android mode:</p>

<pre><code>pioggia.beginDraw();
pioggia.background(0,0);     //or clear()
for(int i = 0; i&lt;gocceNum; i++){
   gocce[i][2] = (gocce[i][2]+gocceSpX*0.25)%back1.width;
   gocce[i][3] = (gocce[i][3]+gocceSpY*0.25)%back1.height;
   pioggia.set((int)gocce[i][2],(int)gocce[i][3], #355B4A);
}
pioggia.endDraw();
copy(pioggia, (int)quantize(disp*0.4, scalaH), 0, sw, sh, 0, 0, width, height);
</code></pre>

<p>"pioggia" is the PGraphics object, gocce is a 2D array of float values.
Any help or hint would be super awesome ç_ç</p>
]]></description>
   </item>
   <item>
      <title>How would I use PGraphics in a class?</title>
      <link>https://forum.processing.org/two/discussion/16505/how-would-i-use-pgraphics-in-a-class</link>
      <pubDate>Mon, 09 May 2016 09:28:57 +0000</pubDate>
      <dc:creator>lilmilkman</dc:creator>
      <guid isPermaLink="false">16505@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I'm pretty new to programming, and am working on a pretty basic drawing program. See I am trying to add undo and redo buttons. I want them to be able to  affect the things I draw in the PGraphics, if that makes sense. Is there a way to fix this? Sorry if the code is excessive...</p>

<pre><code>PGraphics pg;
boolean controlDown = false;
boolean shiftDown = false;
int bgColor = 255;
int pColor = 0;
int pAlpha = 255;
int selector = 0;

int pSize = 5;
int eSize = 5;

boolean drawing = false;
boolean doOnce = false;

Undo undo;

void setup() {

  size(900, 600);
  smooth();

  pg = createGraphics(width, height);

  undo = new Undo(10);
}

void draw() {

  background(bgColor);

  if(mouseX &gt; 142) {
    noCursor();
  } else {

    cursor();
  }

  noFill();
  stroke(0);  
  if(selector == 0) {

  ellipse(mouseX, mouseY, pSize + 2, pSize + 2);
  } else {

    ellipse(mouseX, mouseY, eSize + 2, eSize + 2);
  }
}

void pencil() {

  if (mousePressed) {

    if (mouseX &gt; 142) {

      pg.beginDraw();
      pg.stroke(pColor, pAlpha);
      pg.strokeWeight(pSize);
      pg.strokeJoin(ROUND);
      pg.line(mouseX, mouseY, pmouseX, pmouseY);
      pg.endDraw();
      image(pg, 0, 0);
    }
  }
}



void mousePressed() {

  if (mouseX &gt; 142) {

    drawing = true;
  } else {

    drawing = false;
  }
}

void mouseReleased() {

  drawing = false;
  doOnce = false;

  if(mouseX &gt; 142 || mouseX &gt; 18 &amp;&amp; mouseX &lt; 67 &amp;&amp; mouseY &gt; 534 &amp;&amp; mouseY &lt; 586) {

  undo.takeSnapshot();
  }
}

void mouseClicked() {

  println(mouseX, mouseY);
}

void keyPressed() {

  if (key == CODED) {

    if (keyCode == CONTROL) {

      controlDown = true;
    }
    if (keyCode == SHIFT) {

      shiftDown = true;
    }

    return;
  }

  if (controlDown) {

    if (keyCode == 'Z') {

      if (shiftDown) {

        undo.redo();
      } else {

        undo.undo();
      }
    }

    return;
  }
}

void keyReleased() {

  if (key == CODED) {

    if (keyCode == CONTROL) {

      controlDown = false;
    }

    if (keyCode == SHIFT) {

      shiftDown = false;
    }
  }
}


class Undo {

  int undoSteps = 0, redoSteps = 0; 

  CircImgCollection images;

  Undo(int levels) {

    images = new CircImgCollection(levels);
  }

  public void takeSnapshot(){

    undoSteps = min(undoSteps+1, images.amount-1);
    redoSteps = 0;
    images.next();
    images.capture();
  }

  public void undo() {

    if (undoSteps &gt; 0) {

      undoSteps--;
      redoSteps++;
      images.prev();
      images.show();
    }
  }

  public void redo() {

    if (redoSteps &gt; 0) {

      undoSteps++;
      redoSteps--;
      images.next();
      images.show();
    }
  }
}


class CircImgCollection {

  int amount, current;  
  PImage[] img;

  CircImgCollection(int amountOfImages) {

    amount = amountOfImages;

    img = new PImage[amount];

    for (int i=0; i &lt; amount; i++) {

      img[i] = createImage(width, height, RGB);
      img[i] = get();
    }
  }

  void next() {

    current = (current + 1) % amount;
  }

  void prev() {

    current = (current - 1 + amount) % amount;
  }

  void capture() {

    img[current] = get();
  }

  void show() {

    image(img[current], 0, 0);
  }
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>